<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增角色</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../static/layui/css/layui.css" tppabs="https://www.layui.site/layui/dist/css/layui.css"  media="all">
    <script src="../../static/layui/layui.js" charset="utf-8"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
</head>
<body>

<form  class="layui-form" method="post" action="../../role/add">
    <div class="layui-form-item">
        <div class="layui-inline">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
<!--            <input type="text" name="roleName" lay-verify="required" lay-reqtext="角色名称是必填项，岂能为空？" placeholder="请输入角色名称" autocomplete="off" class="layui-input">-->
            <input type="text" id="role_name" name="roleName" placeholder="请输入角色名称" autocomplete="off" class="layui-input" required="required">
        </div>
    </div>

<!--            <input type="text" name="createBy" lay-verify="required" lay-reqtext="兄弟，创建人是必填项" placeholder="请输入创建人姓名" autocomplete="off" class="layui-input" width="100">-->
            <input type="text" style="display: none" id="create_by" name="createBy" placeholder="请输入创建人姓名" autocomplete="off" class="layui-input" width="100">




    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea id="remark" name="remark" placeholder="请输入备注内容" class="layui-textarea"></textarea>
        </div>
    </div>

        <div class="layui-inline">
            <label class="layui-form-label">菜单</label>
            <div class="layui-input-inline">
                <input type="text"  name="menuNameList" id="menuNameList" lay-verify="required" placeholder="请选择菜单"
                       autocomplete="off" class="layui-input" onclick="load_menuTree()" style="width: 350px"/>
                <input type="text" name="menuIdList" id="menuIdList" hidden/>
            </div>
        </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="button"  onclick="addRole()" class="layui-btn" value="确认" id="add">
<!--            <button type="submit"  class="layui-btn" lay-filter="demo1" lay-submit="">确认</button>-->
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    </div>

    <script>
        function load_menuTree() {
            layer.open({
                type: 2
                , title: false //不显示标题栏
                , closeBtn: 1
                , area: ['500px','400px']
                , shade: 0.8
                , btn: ['确定', '取消']
                , btnAlign: 'c'
                , offset: 'auto'
                , scrollbar: false
                , content: 'setMenu.html'
            });
        }
        function addRole()
        {
            var roleName=$("#role_name").val();
            var createBy=$("#create_by").val();
            var menuIdList=$("#menuIdList").val();
            var remark=$("#remark").val();
            $.post("/ams-admin/role/add",{roleName:roleName,createBy:createBy,remark:remark,menuIdList:menuIdList} ,function (data)
            {
                if (data.code === 0) {
                    layer.alert(("新增角色成功！"),function (){
                        window.parent.location.reload()
                        parent.layer.close(index)
                    })
                } else {
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            }).then()
        }
    </script>

</form>

</body>
</html>